import numpy as np
np.set_printoptions(threshold=np.inf)

# 处理数据的库
import numpy as np
import pandas as pd

# TensorFlow的库
from tensorflow import keras


def predict_two_data_by_model(type,kuan,hou):
    # file_path = url_for('static', filename='重建模型全部数据表格版.xlsx')
    # print(file_path)
    if type == 'hips':
        # 获取数据集
        data = pd.read_excel('static/data_file/重建模型全部数据表格版.xlsx', engine='openpyxl', usecols=['臀宽', '臀厚'])
        data = np.array(data)
        target = pd.read_excel('static/data_file/重建模型全部数据表格版.xlsx', engine='openpyxl', usecols=['臀围'])
        target = np.array(target)
        new_model = keras.models.load_model('static/data_file/男臀围预测模型.h5')
    elif type == 'waist':
        # 获取数据集
        data = pd.read_excel('static/data_file/重建模型全部数据表格版.xlsx', engine='openpyxl', usecols=['腰宽', '腰厚'])
        data = np.array(data)
        target = pd.read_excel('static/data_file/重建模型全部数据表格版.xlsx', engine='openpyxl', usecols=['腰围'])
        target = np.array(target)
        new_model = keras.models.load_model('static/data_file/男腰围预测模型.h5')
    elif type == 'chest':
        # 获取数据集
        data = pd.read_excel('static/data_file/重建模型全部数据表格版.xlsx', engine='openpyxl', usecols=['胸宽', '胸厚'])
        data = np.array(data)
        target = pd.read_excel('static/data_file/重建模型全部数据表格版.xlsx', engine='openpyxl', usecols=['胸围'])
        target = np.array(target)
        new_model = keras.models.load_model('static/data_file/男胸围预测模型.h5')
    from sklearn.model_selection import train_test_split
    # test_size 指的是划分的训练集和测试集的比例
    # test_size 默认值为0.25 表示数据分四份，测试集占一份
    x_train_all, x_test, y_train_all, y_test = train_test_split(data, target, random_state=7, test_size=0.1)
    x_train, x_valid, y_train, y_valid = train_test_split(x_train_all, y_train_all, random_state=11, test_size=0.1)


    aver_train = np.mean(x_train, axis=0)
    std_train = np.std(x_train, axis=0)

    aver_test = np.mean(y_train, axis=0)
    std_test = np.std(y_train, axis=0)

    # print(aver_train, std_train)
    # print(aver_test, aver_test)
    data = np.array([int(kuan), int(hou)])
    data = (data - aver_train) / std_train
    # print(x_train.shape)
    data = data.reshape(1, 2)
    # print(data.shape)
    return int((new_model.predict(data) * std_test + aver_test)[0][0])

if __name__ == "__main__":
    predict_two_data_by_model('waist', 333, 267)